package Thread.demo7.CountDownLatch;

import java.util.concurrent.CountDownLatch;

/**
 * 例子： 其他员工等我做完模块1，他们才能继续做下去
 *
 * @author
 * @create 2018-10-10 12:35
 **/
public class CountDownLatchTest2 {

    public static void main(String[] args) {

        CountDownLatch countDownLatch = new CountDownLatch(1);

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(5);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("我终于做完了");
                countDownLatch.countDown();
            }
        }).start();

        for (int i = 0; i < 5; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    System.out.println("等我做完第一个模块");
                    try {
                        countDownLatch.await();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("我终于做完第一个模块，他们可以开始工作了");
                }
            }).start();
        }


    }
}
